package com.shuma.permissionservice.controller;


import com.shuma.permissionservice.service.PermissionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/rpc/permission")
@RequiredArgsConstructor
public class RPCController {

    private final PermissionService permissionService;

    @PostMapping("/bind-default-role")
    public void bindDefaultRole(@RequestParam Long userId) {
        permissionService.bindDefaultRole(userId);
    }

    @GetMapping("/get-role-code")
    public String getUserRoleCode(@RequestParam Long userId) {
        return permissionService.getUserRoleCode(userId);
    }

    @GetMapping("/user-id-list-by-role")
    List<Long> getUserIdsByRole(@RequestParam("roleCode") String roleCode){
        return permissionService.getAllUserRole(roleCode);
    };

    @PostMapping("/upgrade-admin")
    public void upgradeToAdmin(@RequestParam Long userId) {
        permissionService.upgradeToAdmin(userId);
    }

    @PostMapping("/downgrade-user")
    public void downgradeToUser(@RequestParam Long userId) {
        permissionService.downgradeToUser(userId);
    }
}
